package cn.innosmart.aq.camera;

import android.os.AsyncTask;
import android.util.Log;

import com.tutk.IOTC.IOTCAPIs;
import com.tutk.IOTC.st_LanSearchInfo2;

import java.util.ArrayList;
import java.util.List;

/**
 * 局域网搜索的异步任务
 * Created by sabonis on 11/14/14.
 * With MBPR
 */
public class GetLanDeviceTask extends AsyncTask<Void, Void, List<GetLanDeviceTask.LANSearchResult>> {

    @Override
    public List<LANSearchResult> doInBackground(Void... voids) {
        Log.d("kukuri2", "GetLanDevice doInBackground called");
        ArrayList<LANSearchResult> results = new ArrayList<>();
        int num[] = new int[1];
        // 1000 is timeout in msec
        st_LanSearchInfo2[] arrResp = IOTCAPIs.IOTC_Lan_Search2(num, 1000);
        if (arrResp != null && arrResp.length > 0) {
            for (st_LanSearchInfo2 resp : arrResp) {
                results.add(new GetLanDeviceTask.LANSearchResult(resp));
            }
        }
        return results;
    }

    public class LANSearchResult {

        public String uid;
        public String ip;
        public int port;

        public LANSearchResult(st_LanSearchInfo2 resp) {
            this.uid = new String(resp.UID);
            this.ip = new String(resp.IP);
            this.port = resp.port;
        }
    }
}
